#define DEBUG
#include <cstdio>
#define MAXN 100000
#define MAXC 30

using namespace std;

int min(int a, int b) {
  return a<b ? a : b;
}

int max(int a, int b) {
  return a>b ? a : b;
}

class SegmentTree {
public:
  int color[4*MAXN+1], mark[4*MAXN+1], c;

  void init(int o, int l, int r) {
    color[o]=2;
    if (l!=r) {
      init(o*2, l, (l+r)/2);
      init(o*2+1, (l+r)/2+1, r);
    }
  }

  void markDown(int o, int l, int r) {
    if (mark[o]) {
      color[o]=(1<<mark[o]);
      if (l!=r) {
	mark[o*2]=mark[o*2+1]=mark[o];
      }
      mark[o]=0;
    }
  }

  void set(int o, int l, int r, int tl, int tr, int tc) {
    markDown(o, l, r);
    if (l==tl && r==tr) {
      mark[o]=tc;
      markDown(o, l, r);
    } else {
      int mid=(l+r)/2;
      if (tl<=mid && tr>=l) {
	set(o*2, l, mid, max(l, tl), min(mid, tr), tc);
      }
      if (tl<=r && tr>mid) {
	set(o*2+1, mid+1, r, max(mid+1, tl), min(r, tr), tc);
      }
      markDown(o*2, l, mid);
      markDown(o*2+1, mid+1, r);
      color[o] = color[o*2]|color[o*2+1];
    }
  }

  int get(int o, int l, int r, int tl, int tr) {
    int ret=0;
    markDown(o, l, r);
    if (l==tl && r==tr) {
      ret |= color[o];
    } else {
      int mid=(l+r)/2;
      if (tl<=mid && tr>=l) {
	ret |= get(o*2, l, mid, max(l, tl), min(mid, tr));
      }
      if (tl<=r && tr>mid) {
	ret |= get(o*2+1, mid+1, r, max(mid+1, tl), min(r, tr));
      }
    }
    return ret;
  }
};

int main() {
#ifdef DEBUG
  freopen("3.in", "r", stdin);
  freopen("3.out", "w", stdout);
#endif

  static SegmentTree sgt;
  int n, c, m;
  scanf("%d %d %d", &n, &c, &m);
  sgt.c=c;
  sgt.init(1, 1, n);
  for (int i=1; i<=m; i++) {
    char ch;
    scanf(" %c", &ch);
    if (ch=='P') {
      int x, y;
      scanf("%d %d", &x, &y);
      int temp;
      if (x<=y) {
	temp=sgt.get(1, 1, n, x, y);
      } else {
	temp=sgt.get(1, 1, n, y, x);
      }
      int ans=0;
      for (int i=0; i<=c; i++) {
	ans += (temp>>i)&1;
      }
      printf("%d\n", ans);
    } else {
      int x, y, t;
      scanf("%d %d %d", &x, &y, &t);
      if (x<=y) {
	sgt.set(1, 1, n, x, y, t);
      } else {
	sgt.set(1, 1, n, y, x, t);
      }
    }
  }

  fclose(stdin);
  fclose(stdout);
}
